/*
 Ben Humphrey (DigiBen)
 Game Programmer
 DigiBen@GameTutorials.com
 Co-Web Host of www.GameTutorials.com
	Date:			 07/12/2001											 
 First Update:           - Rafael Martins
 Updates: 24/06/2004 - Rodrigo L. S. Silva - Code organization
 		 	 30/04/2007 - Rodrigo L. S. Silva - Replace de "windows.h" include and 
															associated Functions
*/

#ifndef _CAMERA_H
#define _CAMERA_H

// This is our basic 3D point/vector class
struct CVector3
{
   public:
	
	// A default constructor
	CVector3() {}

	// This is our constructor that allows us to initialize our data upon creating an instance
	CVector3(float X, float Y, float Z) 
	{ 
		x = X; y = Y; z = Z;
	}

	// Here we overload the + operator so we can add vectors together 
	CVector3 operator+(CVector3 vVector)
	{
		// Return the added vectors result.
		return CVector3(vVector.x + x, vVector.y + y, vVector.z + z);
	}

	// Here we overload the - operator so we can subtract vectors 
	CVector3 operator-(CVector3 vVector)
	{
		// Return the subtracted vectors result
		return CVector3(x - vVector.x, y - vVector.y, z - vVector.z);
	}
	
	// Here we overload the * operator so we can multiply by scalars
	CVector3 operator*(float num)
	{
		// Return the scaled vector
		return CVector3(x * num, y * num, z * num);
	}

	// Here we overload the / operator so we can divide by a scalar
	CVector3 operator/(float num)
	{
		// Return the scale vector
		return CVector3(x / num, y / num, z / num);
	}

	float x, y, z;						
};

// This is our camera class
class CCamera 
{
   private:
   	CVector3 m_vPosition;  // The camera's position
   	CVector3 m_vView;		  // The camera's view					
   	CVector3 m_vUpVector;  // The camera's up vector
   	CVector3 m_vStrafe;	  // The camera's strafe vector		

		int mousePosX, mousePosY;			
		int windowSizeX, windowSizeY;	
   
   public:
   	// Our camera constructor
   	CCamera();			
   
   	// These are are data access functions for our camera's private data
   	CVector3 Position()  {	return m_vPosition;        }
   	CVector3 View()		{	return m_vView;			   }
   	CVector3 UpVector()  {	return m_vUpVector;		   }
   	CVector3 Strafe()	   {	return m_vStrafe;          }
   	
   	// This changes the position, view, and up vector of the camera.
   	// This is primarily used for initialization
   	void PositionCamera(float positionX, float positionY, float positionZ,
                          float viewX,     float viewY,     float viewZ,
   						     float upVectorX, float upVectorY, float upVectorZ);
   
   	// This rotates the camera's view around the position depending on the values passed in.
   	void RotateView(float angle, float X, float Y, float Z);
   
   	// This moves the camera's view by the mouse movements (First person view)
   	void SetViewByMouse(); 
   
   	// This rotates the camera around a point (I.E. your character).
   	void RotateAroundPoint(CVector3 vCenter, float X, float Y, float Z);
   
   	// This strafes the camera left or right depending on the speed (+/-) 
   	void StrafeCamera(float speed);
   
   	// This will move the camera forward or backward depending on the speed
   	void MoveCamera(float speed);
   
   	// This updates the camera's view and other data (Should be called each frame)
   	void Update();
   
   	// This uses gluLookAt() to tell OpenGL where to look
   	void Look();
   	
   	void GetPosition(float *pos)
   	{
         pos[0] = m_vPosition.x;
         pos[1] = m_vPosition.y; 
         pos[2] = m_vPosition.z;                   
      }

		// Set/Get Cursor (mouse) position
		void SetCursorPosition(int  x, int  y);
		void GetCursorPosition(int *x, int *y);

		// Set/Get Window Size
		void SetWindowSize(int  x, int  y);
		void GetWindowSize(int *x, int *y);		
};
#endif

